package com.doghome.mysb.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import com.doghome.mysb.annotaion.CheckPermission;
import com.doghome.mysb.utils.AjaxResult;
import com.doghome.mysb.utils.JwtUtil;

@RestController
public class BizController {
	
	@Autowired
	private StringRedisTemplate redisTemplate;
	
	@PostMapping("/add")
	@CheckPermission("1")
	public AjaxResult add() {
		return AjaxResult.success();
	}
	
	@PostMapping("/edit")
	@CheckPermission({"2","3"})
	public AjaxResult edit() {
		return AjaxResult.success();
	}
	
	@GetMapping("/query")
	public AjaxResult query() {
		return AjaxResult.success();
	}
	
	@GetMapping("/exit")
	public AjaxResult exit(@RequestHeader(name = "Authorization") String token) {
		Long userID = JwtUtil.getUserID(token);
		if(redisTemplate.delete(userID.toString())){
			return AjaxResult.success();
		}
		return AjaxResult.error();
	}
}
